import BaseController from "../../cfw/mvc/BaseController";
import SDKManager from "../SDKManager";
import ModuleManager, { ModuleID } from "../../cfw/module/ModuleManager";
import GameItemModel from "../base/GameItemModel";
import GlobalEvent from "../../cfw/event/GlobalEvent";
import { EventName } from "../../public/Config";


export enum ExportType {
    EXPORT1,
    EXPORT2,
    EXPORT3,

}

export default class BigExportC extends BaseController {


    private static ins: BigExportC;

    static instance() {
        if (!this.ins) {
            this.ins = new BigExportC()
        }
        return this.ins;
    }

    protected callback: Function[] = [];

    intoExport1(func?: Function) {
        let list = SDKManager.getChannel().getAdData();
        if (list.length <= 0) {
            if (func) {
                func()
            }
            return
        }
        this.callback[ExportType.EXPORT1] = func;
        this.pushView('prefabs/appBoxAd/BigExportPage1', 'BigExportPage1', SDKManager.getChannel(), ModuleManager.getLoader(ModuleID.PUBLIC))
    }

    intoExport2(func?: Function) {
        let list = SDKManager.getChannel().getAdData();
        if (list.length <= 0) {
            if (func) {
                func()
            }
            return
        }
        this.callback[ExportType.EXPORT2] = func;
        this.pushView('prefabs/appBoxAd/BigExportPage2', 'BigExportPage2', SDKManager.getChannel(), ModuleManager.getLoader(ModuleID.PUBLIC))
    }

    clickPage1Game(model: GameItemModel) {
        model.subPriority()
        SDKManager.getChannel().navigate2Mini(model)
        SDKManager.getChannel().sortAdData()
    }

    clickPage2Game(model: GameItemModel) {
        SDKManager.getChannel().navigate2Mini(model)
    }


    intoExport3(func?: Function) {
        let list = SDKManager.getChannel().getAdData();
        if (list.length <= 0) {
            if (func) {
                func()
            }
            return
        }
        this.callback[ExportType.EXPORT3] = func;
        this.pushView('prefabs/appBoxAd/BigExportPage3', 'BigExportPage3', SDKManager.getChannel(), ModuleManager.getLoader(ModuleID.PUBLIC))
    }

    clickPage3Game(model: GameItemModel) {
        SDKManager.getChannel().navigate2Mini(model)
    }

    closeView(type: ExportType) {
        if (this.callback[type]) {
            this.callback[type]();
            this.callback[type] = null;
        }
    }
}



